<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 获取代理IP日志记录
 *
 * @icon fa fa-circle-o
 */
class DataOverview extends Backend
{

    public function import()
    {
        parent::import();
    }

    /**
     * 查看
     */
    public function index()
    {
        return $this->view->fetch();
    }
    // 数据概览
    public function overview(){
            $data= $this->curl_post('http://task.phckz.730893.com/admin/overview');
            $data=json_decode($data,true);
            $datas = $data['data'];
            return json($datas);
    }
    // Reap任务用户统计查询
    public function usermange(){
        if ($_GET) {
            $start = $_GET['start'];
            $end = $_GET['end'];
            // dump($start);dump($end);die;
            $upicker= $this->curl_get('http://task.phckz.730893.com/admin/usermange?upicker[]='.urlencode($start).'&upicker[]='.urlencode($end));
            $upicker=json_decode($upicker,true);
            $upickers = $upicker['data']['data'];
            return json($upickers);
        }else{
            $upicker= $this->curl_get('http://task.phckz.730893.com/admin/usermange');
            $upicker=json_decode($upicker,true);
            $upickers = $upicker['data']['data'];
            return json($upickers);
        }
    }
    // Config数据查询
    public function configdis(){
        if ($_GET) {
            $start = $_GET['start'];
            $end = $_GET['end'];
            $url = 'http://task.phckz.730893.com/admin/configdis?picker[]='.urlencode($start).'&picker[]='.urlencode($end);
            $configdis= $this->curl_get($url);
            $configdis=json_decode($configdis,true);
            $configdiss = $configdis['data'];
            return json($configdiss);
        }else{
            $configdis= $this->curl_get('http://task.phckz.730893.com/admin/configdis');
            $configdis=json_decode($configdis,true);
            $configdiss = $configdis['data'];
            return json($configdiss);
        }
    }
    // Record和Result记录统计
    public function record_result(){
        $result= $this->curl_get('http://task.phckz.730893.com/admin/record-result');
        $result=json_decode($result,true);
        $results = $result['data'];
        return json($results);
    }
    // 任务轮数分配
    public function job_round(){
        $job= $this->curl_get('http://task.phckz.730893.com/admin/job-round');
        $job=json_decode($job,true);
        $jobs = $job['data'];
        return json($jobs);
    }
    /**
     * 查看请求记录统计
     */
    public function statistics(){
        return $this->view->fetch();
    }
    // 请求日志(当日数量)统计
    public function logs_total(){
        if ($_GET) {
            $type = $_GET['type'];
            // dump($start);dump($end);die;
            $logtotal= $this->curl_get('http://task.phckz.730893.com/admin/logs-total?type='.$type);
            $logtotal=json_decode($logtotal,true);
            $logtotals = $logtotal['data'];
            return json($logtotals);
        }else{
            $logtotal= $this->curl_get('http://task.phckz.730893.com/admin/logs-total');
            $logtotal=json_decode($logtotal,true);
            $logtotals = $logtotal['data'];
            return json($logtotals);
        }
    }

    // 日志历史数据统计列表查询
    public function logs(){
        if ($_GET) {
            $start = $_GET['start'];
            $end = $_GET['end'];
            // dump($start);dump($end);die;
            $logs= $this->curl_get('http://task.phckz.730893.com/admin/logs?picker[]='.urlencode($start).'&picker[]='.urlencode($end));
            $logs=json_decode($logs,true);
            $logss = $logs['data'];
            return json($logss);
        }else{
            $logs= $this->curl_get('http://task.phckz.730893.com/admin/logs');
            $logs=json_decode($logs,true);
            $logss = $logs['data'];
            return json($logss);
        }
    }

    // 数据库流量信息
    public function mysql(){
        $mysql= $this->curl_get('http://task.phckz.730893.com/admin/mysql');
        $mysql=json_decode($mysql,true);
        $mysqls = $mysql['data'];
        return json($mysqls);
    }
    // 数据库进程信息
    public function processes(){
        $processes= $this->curl_get('http://task.phckz.730893.com/admin/mysql/processes');
        $processes=json_decode($processes,true);
        $processess = $processes['data'];
        return json($processess);
    }
    public static function curl_get($url){
       $testurl = $url;
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $testurl);
        //参数为1表示传输数据，为0表示直接输出显示。
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //参数为0表示不带头文件，为1表示带头文件
       curl_setopt($ch, CURLOPT_HEADER,0);
       $output = curl_exec($ch);
       curl_close($ch);
       return $output;
    }

    public static function curl_post($url){
        $curl = curl_init();
        //设置提交的url
        curl_setopt($curl, CURLOPT_URL, $url);
        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_HEADER, 0);
        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //设置post方式提交
        curl_setopt($curl, CURLOPT_POST, 1);
        //执行命令
        $data = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);
        //获得数据并返回
        return $data;
    }
}
